package upicgame.interceptors;

import org.springframework.web.servlet.HandlerInterceptor;
import upicgame.entity.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @program: upicgame
 * @description: 管理员拦截器
 * @author: lhq
 * @create: 2019-12-30 16:09
 */
public class AdminInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception{
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String uri = request.getRequestURI();
		System.out.println(uri);
		if ("/upicgame/admin.jsp".equals(uri) && user.getUserType().equals("admin")){
			return true;
		}
		response.sendRedirect("index.jsp");
		return true;
	}
}
